package com.anlu.base.function;

import com.alibaba.fastjson2.JSON;
import com.anlu.base.function.mode.CalculateFunction;
import com.anlu.base.function.mode.LogFunction;
import com.anlu.base.function.mode.MyFunction;
import com.anlu.base.model.Person;

import java.util.function.Function;
import java.util.function.Supplier;

public class controller {
    public static void main(String[] args) {
        MyFunction myFunction = () -> System.out.println("hello world");

        myFunction.execute();

        test1();

        test2();

        test3();

        test4();

        test5();
    }

    static void test1(){
        CalculateFunction calculateFunction = (a,b)->a+b;
        int result = calculateFunction.cal(3,4);
        System.out.println(result);

    }

    static void test2(){
        LogFunction function = msg -> System.out.println(msg);
        function.log("hello");

        function.logError("安悦心");
    }

    static void test3(){

        Function<Integer,String> function = val -> "Hello:"+val.toString();
        String res = function.apply(1);
        System.out.println(res);
    }

    static void test4(){

        Person p = new Person(10,"降世神通");
        String jsonString = JSON.toJSONString(p);

        Function<String, Person> function = msg ->  JSON.parseObject(msg,Person.class);
        Person person = function.apply(jsonString);
        System.out.println(person.toString());
    }

    static void test5(){
        Supplier<Person> supplier = () -> new Person(18,"瑞瑞");
         Person person =  supplier.get();
        System.out.println(person.getName());
    }
}
